import java.util.Scanner;
import java.util.*;
/*
 **@Author:刘淑钰
 **Created on 2021/12/8
 */
public class Main {
    public static int res[][];
    public static int distance;
    public static int n;

    public void solution(int re[][]){
        int i,k;
        for(i=1;i<=n;i++){
            if((re[0][i]-re[0][i-1])<distance){
                for(k=1;k!=i;k++)
                    if((re[0][i]-re[0][k])>=distance)
                        if((re[2][k]+re[1][i])>re[2][i-1])
                            re[2][i]=re[2][k]+re[1][i];
                if(re[2][i]<re[2][i-1])
                    re[2][i]=re[2][i-1];
                if(re[0][i]<distance){
                    if(re[1][i]>re[2][i-1])
                        re[2][i]=re[1][i];
                    else
                        re[2][i]=re[2][i-1];
                }
            }
            else{
                re[2][i]=re[2][i-1]+re[1][i];
            }
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Main test = new Main();
        n = in.nextInt();
        res = new int[3][n + 1];
        int i, j,m;
        for (i = 0; i < 3; i++)
            for (j = 0; j <= n; j++)
                res[i][j] = 0;//初始化 re

        for(i=1;i<=n;i++){
            m=in.nextInt();
           res[0][i]=m;
        }
        for(i=1;i<=n;i++)
        {
            m=in.nextInt();
            res[1][i]=m;
        }
        distance=in.nextInt();

        test.solution(res);
        System.out.print(res[2][n]);

    }

}

